import React from 'react'
import PropTypes from 'prop-types'

class Page extends React.Component{
    static childContextTypes = {
        user: PropTypes.string
    }
    state = {
        user: '蜗牛'
    }
    getChildContext(){
        return this.state
    }
    render(){
        return (
            <div>
                <h1>我是{this.state.user}</h1>
                <Slider/>
            </div>
        )
    }
}

class Slider extends React.Component{
    render(){
        return (
            <div>
                <h1>侧边栏</h1>
                <SliderHeader />
            </div>
        )
    }
}

class SliderHeader extends React.Component{
    static contextTypes = {
        user: PropTypes.string
    }
    render(){
        return (
            <h1>{this.context.user}的侧边栏头边</h1>
        )
    }
}

//无状态组件
//function SliderHeader(props,context){
//    return (
//        <h1>{context.user}的侧边栏头边</h1>
//    )
//}
//SliderHeader.contextTypes = {
//    user: PropTypes.string
//}
